<template>
	<div>
		<server-question v-on:toParent="changeDescrible" :data="data" :describle="describle" :initData="getInitData"></server-question>
	</div>
</template>

<script>
	import { mapMutations, mapActions, mapGetters } from "vuex";
	import ServerQuestion from "../../../components/servers/serverQuestion";
    import { Toast } from '../../../utils/toast.js';
    import { getHrefParams } from '../../../utils/zx';
	import axios from 'axios';
	export default {
        props: {
         	
        },
        data () {
            return {
                describle: null,
                data: null,
            }
        },
        computed:{
       		...mapGetters('wxh',[
                'sessionId',
                'userInfo'
            ]),
            hasUserInfo() {
                return Object.keys(this.userInfo).length;
            },
        },
        mounted(){
            console.log(this.sessionId,'sessionId问题列表');
            this.initData();
		}
		,
		watch: {
			describle(newValue, oldValue) {
				this.initData(newValue)
            },
            hasUserInfo(newValue, oldValue){
                console.log(newValue,'hasUserInfo')
                if(newValue){
                    this.initData();
                }
            }
		}
		,
		methods: {
			changeDescrible(val){
				this.describle = val;
			},
			//对接运营接口
			getInitData(){
                //此接口如果传参就是搜索
				let params = {
					"describle":this.describle,
					"enterpriseCode":"NJXS"
        		};
				let config = {
					url:window.api.customer_host +'/commonQuestionVue/queryAnswerList',
	            	method: 'POST',
	            	data: params,
	            	headers: {'sessionId': this.sessionId, 'Content-Type':'application/json', 'Accept' : 'application/json'},
                }
                console.log(config,'入參')
				axios(config).then((res)=>{
                    console.log('获取数据成功',res);
					if(res.data.returnCode == 0) {
						Toast({
						  message: res.data.msg,
						  type: 'fail',
						  duration: 2000
						});
						return
					}
					this.data = res.data.data[0].results;
				})
			},
			async initData(val) {
			
		        //调用個人中心的方法刷新用户信息 防止vuex用户信息失效
				// reFreshUserInfo(this);
				//初始化数据
		        this.getInitData();
			}
		},
        components: {
	        "server-question": ServerQuestion,
	    },
       	
    }
</script>

<style>
</style>